package com.itheima_02;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class Test01 {
    public static void main(String[] args) throws DocumentException {
        ArrayList<BookStroe> list = new ArrayList<>();
        SAXReader saxReader = new SAXReader();
        Document read = saxReader.read(new File("day17_demo\\src\\com\\itheima_01\\test01.xml"));
        Document document = read.getDocument();
        Element rootElement = document.getRootElement();
        List<Element> book = rootElement.elements("book");
        for (Element element : book) {
            Attribute id = element.attribute("category");
            String idvalue = id.getValue();
            Element title = element.element("title");
            String titleText = title.getText();
            Element author = element.element("author");
            String authorText = author.getText();
            Element year = element.element("year");
            String yearText = year.getText();
            Element price = element.element("price");
            String priceText = price.getText();
            BookStroe book1 = new BookStroe(idvalue, titleText, authorText,Integer.parseInt(yearText), Double.parseDouble(priceText));
           list.add(book1);

       }
        System.out.println(list);
    }
}

